<!doctype html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="./css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" type="text/css" href="./css/style.css" />
		<link rel="stylesheet" type="text/css" href="./css/serverURLManage.css" />
	</head>

	<body>
		<!-- 页面 -->
		<header class="mui-bar mui-bar-nav">
			<a id="backLogin" class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">检验码</h1>
		</header>
		<div class="mui-content">
			<form class="mui-input-group">
				<div class="mui-input-row">
					<label>服务器地址：</label>
					<input id="checkCode" type="text" class="mui-input-clear" placeholder="请输入检验码">
				</div>
			</form>
			<div class="btn">
				<button id="getServerURL" type="button" class="mui-btn mui-btn-primary">确定</button>
			</div>
		</div>


		<!-- JS部分 -->
		<script src="./js/mui.min.js"></script>
		<script src="js/jquery-2.1.1.min.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			// mui.init()
			
			// 判断网络连接状态
			function isNetWork() {
				var NetStateStr = '未知';
				var types = {};
				types[plus.networkinfo.CONNECTION_UNKNOW] = "未知";
				types[plus.networkinfo.CONNECTION_NONE] = "未连接网络";
				types[plus.networkinfo.CONNECTION_ETHERNET] = "有线网络";
				types[plus.networkinfo.CONNECTION_WIFI] = "WiFi网络";
				types[plus.networkinfo.CONNECTION_CELL2G] = "2G蜂窝网络";
				types[plus.networkinfo.CONNECTION_CELL3G] = "3G蜂窝网络";
				types[plus.networkinfo.CONNECTION_CELL4G] = "4G蜂窝网络";
				NetStateStr = types[plus.networkinfo.getCurrentType()];
				return (NetStateStr === "未知") || (NetStateStr === "未连接网络") ? false : true;
			}
			
			var basisURl = "https://www.jxsjcrj.cn/jxjcsys/MobileCopy/KeyCheckHandler.ashx"
			function getURL(checkCode) {
				var json;
				var url = basisURl + '?action=getserverurl&vcode=' + checkCode;
				$.ajax({
					url: url,
					async: false,
					dataType: "json",
					success: function(data) {
						json = data;
					},
					error: function(xhr) {
						//alert('error:' + xhr.statusText);
						json = '{"status":"error","msg":"' + xhr.statusText + '"}';
					}
				});
				return json;
			}
			mui.plusReady(function () {
				// 设置检验码保留
				var selfWindow = plus.webview.currentWebview();
				if (selfWindow.checkCode != null) {
					$("#checkCode").val(selfWindow.checkCode);
				} else{
					$("#checkCode").val("");
				}
				
			  mui(".btn").on("tap","#getServerURL", function(){
			  	var checkCode = $("#checkCode").val();
					// var checkCode = document.getElementById("checkCode");
					if (checkCode == "") {
						mui.toast('请先填写检验码');
					} else{
						var serverUrl = getURL(checkCode);
						if (serverUrl.url == "") {
							alert("检验码填写错误")
						} else{
							localStorage.setItem("copanyName", serverUrl.companyname)
							localStorage.setItem("serverURL", serverUrl.url);
							localStorage.setItem("checkCodeValue", checkCode);
							// console.log(JSON.stringify(serverUrl));
							// console.log(serverUrl.companyname);
							//var currentPage = plus.webview.currentWebview();
							// var loginPage = currentPage.opener();
							// console.log(loginPage);
							// mui.fire(loginPage,'companyName',{
							// 	companyname: serverUrl.companyname
							// })
							mui.back();
						}
					}
			  })
			})
		</script>
	</body>

</html>
